<template>
  <div class="article-page">

      <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>面经后台</el-breadcrumb-item>
      <el-breadcrumb-item>面经管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card shadow="never" border="false">
      <template #header>
        <div class="header">
          <span>共 {{total}} 条记录</span>
          <el-button @click="$refs.strength.open()"
            icon="el-icon-plus"
            size="small"
            type="primary"
            round>
            添加面经
          </el-button>
        </div>
      </template>
   <el-table
      :data="articlelist"
      style="width: 100%">
      <el-table-column
        prop="stem"
        label="标题"
       >
      </el-table-column>
      <el-table-column
        prop="creator"
        label="作者"
       >
      </el-table-column>
      <el-table-column
        prop="likeCount"
        label="点赞"
       >
      </el-table-column>
          <el-table-column
        prop="views"
        label="浏览量"
         >
       
      </el-table-column>
        <el-table-column
        prop="createdAt"
        label="提交时间"
         >
       
      </el-table-column>
        <el-table-column
      
        label="操作"
         >
      <template #default="{row}">
                <el-button size="small" type="success">查看</el-button>
                <el-button size="small" type="primary" >编辑</el-button>
                <el-button size="small" type="danger" @click="remove(row.id)">删除</el-button>
              </template>
      </el-table-column>
    </el-table>
    <el-pagination
  background
  layout="prev, pager, next"
  :page-size='pageSize' :total="total" @current-change='change'>
</el-pagination>
    </el-card>

<artical-drawer @reload='getarticle()' ref="strength"></artical-drawer>
  </div>
</template>

<script>
import {getArticalAPI,deleteAPI} from '../../api/article'
import articalDrawer from './components/artical-drawer.vue'
// import {} from '../api/article'
export default {
  components: { articalDrawer },
  name: 'article-page',
    data() {
        return {
         
          articlelist:[],
          total:0,
            // 当前页数
            current:1,
            pageSize:5,
            pageTotal:0
        }
      },
  created () {
    this.getarticle()
  },
  methods: {
    fn(xxx){
        // console.log(xxx);
    },
    change(page){
        // console.log(page);
        this.current=page,
        this.getarticle()
    },
   async remove(id){

await  this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })

        // await  this.$message({
        //     type: 'success',
        //     message: '删除成功!'
        //   });





    await deleteAPI(id)


 if(this.current!==1&&this.current===this.pageTotal&&this.articlelist.length==1){
  console.log(this.articlelist);
  this.current--
 }


this.$message({
            type: 'success',
            message: '删除成功!'
          });



    // console.log(i);
    this.getarticle()
    },
    // 封装好请求的接口
   async getarticle(){
       let res=await getArticalAPI(
       { current:this.current,
             pageSize:this.pageSize
       }
       )
       console.log(res);
       this.articlelist=res.data.rows
       this.total=res.data.total,
       this.pageTotal=res.data.pageTotal
    }
    
  }
}
</script>

<style lang="scss" scoped>
.el-card {
  margin-top: 25px;
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 16px;
  }
  .actions {
    font-size: 18px;
    display: flex;
    justify-content: space-around;
    color: #666;
    > i:hover {
      color: rgba(114, 124, 245, 1);
      cursor: pointer;
    }
  }
}
.el-pagination {
  margin-top: 20px;
  text-align: center;
}
.el-breadcrumb {
  margin-top: 10px;
}
.el-form {
  padding-right: 40px;
}
.quill-editor {
  ::v-deep .ql-editor {
    height: 300px;
  }
}
.el-rate {
  padding: 10px 0;
}
.article-preview {
  padding: 0 40px 40px 40px;
  > h5 {
    font-size: 20px;
    color: #666;
    border-bottom: 1px dashed #ccc;
    padding-bottom: 30px;
    margin: 0 0 20px 0;
  }
}
</style>